<template>

	<uv-navbar :fixed="false" :title="title" left-arrow @leftClick="$onClickLeft" />

	<view class="container" style="padding:20rpx;">
		<view style="padding-bottom: 100rpx;">
			<view class="bg-white">


				<view class="section">
					<list-cell :hover="false" padding="50rpx 30rpx">
						<view class="w-100 d-flex flex-column">
							<view class="pay-cell">
								<view>计划标题</view>
								<view class="font-weight-bold">{{order.planTitle}}</view>
							</view>
							<view class="pay-cell">
								<view>计划开始处理时间</view>
								<view class="font-weight-bold">{{order.startTime}}</view>
							</view>
							<view class="pay-cell">
								<view>重复方式</view>
								<view class="font-weight-bold">{{ getruleType(order.ruleType) }}</view>
							</view>
							<view class="pay-cell">
								<view>重复次数</view>
								<view class="font-weight-bold">{{ order.ruleExecNum }}</view>
							</view>
							<view class="pay-cell">
								<view>已生成</view>
								<view class="font-weight-bold">{{ order.ruleAlreadyExecNum }}</view>
							</view>
							<view class="pay-cell">
								<view>下次生成时间</view>
								<view class="font-weight-bold">{{ order.updatedTime }}</view>
							</view>
							<!-- 	<view class="pay-cell">
								<view>最后更新时间</view>
								<view class="font-weight-bold">2022-01-22</view>
							</view> -->
							<!-- 	<view class="pay-cell">
								<view>最后更新人</view>
								<view class="font-weight-bold">xxh</view>
							</view> -->
						</view>
					</list-cell>

					<view class="title">
						生成工单列表
					</view>
					<template v-if="order.workorderBasicList && order.workorderBasicList.length > 0">
						<uv-cell-group>
							<uv-cell v-for="item in order.workorderBasicList" :key="item.id" :title="item.deviceName"
								:value="item.createdTime" :label="item.number" :center="true"></uv-cell>
						</uv-cell-group>
					</template>

					<!-- <text class="copy" @click="copy()">复制</text> -->

					<!-- <uv-steps current="0" direction="column" dot>
						<uv-steps-item :title="activity.acceptStation" :desc="activity.acceptTime" :key="index"
							v-for="(activity, index) in expresssn">
						</uv-steps-item>
					</uv-steps> -->
				</view>
			</view>
		</view>
		<uv-toast ref="uToast" />
	</view>
	<view class="fixed-bottom flex justify-end bg-white p-2" v-if="order.havePaid > 0">
		<view class="mr-1" v-if="order.haveDelivered ==0 && order.haveReceived == 0"><uv-button type="success"
				:plain="true" size="small" text="确认收货" @click="receive(order)"></uv-button></view>
		<view class="mr-1"><uv-button type="error" :plain="true" size="small" text="查看物流"
				@click="getExpresssn()"></uv-button></view>
	</view>
</template>

<script setup>
	import {
		ref,
		computed,
		getCurrentInstance
	} from 'vue'
	import {
		useMainStore
	} from '@/store/store'
	import {
		storeToRefs
	} from 'pinia'
	import {
		onLoad,
		onPullDownRefresh,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		formatDateTime,
		kmUnit
	} from '@/utils/util'
	import {
		reqPlanDetail
	} from "@/api/operate"
	import {
		scoreShopOrderDetail,
		scoreShopReceive,
		getLogistic
	} from '@/api/score'
	const main = useMainStore()
	const {
		proxy
	} = getCurrentInstance();
	const {
		isLogin
	} = storeToRefs(main)
	const title = ref('计划详情')


	const order = ref({
		// product: {
		// 	title: '',
		// 	image: ''
		// }
	})
	const id = ref(0)
	const expresssn = ref([])

	onLoad((option) => {
		console.log("option===", option)
		id.value = option.id
		detail(option.id)
	})
	onPullDownRefresh(() => {
		detail(id.value)
	})

	const detail = async (id) => {
		let {
			data
		} = await reqPlanDetail(id);
		uni.stopPullDownRefresh();
		if (data.data) {
			console.log("huoqudata==", data.data)
			order.value = data.data;
		}
	}

	const getruleType = (ruleType) => {
		if (ruleType == 0) {
			return "每天";
		} else if (ruleType == 1) {
			return "每周周四";
		} else if (ruleType == 2) {
			return "每月";
		} else if (ruleType == 3) {
			return "每年";
		}
	}

	const getExpresssn = async () => {
		if (order.value.haveDelivered == 0) {
			proxy.$refs.uToast.show({
				message: '还未发货，暂无物流信息',
				type: 'error',
			})
			return
		}

		let data = await getLogistic({
			shipperCode: order.value.expressSn,
			logisticCode: order.value.expressNumber
		});
		if (data.success == "false") {
			uni.showToast({
				title: res.reason,
				icon: 'none'
			})
			return
		}
		expresssn.value = data.traces
	}
	//复制文字
	const copy = () => {
		uni.setClipboardData({
			data: order.value.expressNumber
		})
	}

	// 确认收到货
	const receive = async (order) => {
		let data = await scoreShopReceive({
			id: order.id
		});
		if (data) {
			proxy.$refs.uToast.show({
				message: '已签收',
				type: 'success',
			})
			setTimeout(function() {
				detail(order.id)
			}, 1000);
		}
	}
</script>

<style lang="scss" scoped>
	.copy {
		color: #1296db;
		margin-left: 10rpx;
	}

	@mixin arch {
		content: "";
		position: absolute;
		background-color: $bg-color;
		width: 30rpx;
		height: 30rpx;
		bottom: -15rpx;
		z-index: 10;
		border-radius: 100%;
	}

	.section {
		position: relative;

		.title {
			margin: 20rpx;
		}

		&::before {
			@include arch;
			left: -15rpx;
		}

		&::after {
			@include arch;
			right: -15rpx;
		}
	}

	.pay-cell {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: $font-size-base;
		color: $text-color-base;
		margin-bottom: 40rpx;

		&:nth-last-child(1) {
			margin-bottom: 0;
		}
	}

	.invote-box {
		position: absolute;
		width: 100%;
		left: 0;
		top: 0;
		display: flex;
		justify-content: center;
		align-items: center;

		image {
			width: 30rpx;
			height: 30rpx;
		}
	}

	.btn-box {
		background-color: #ffffff;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 120rpx;
		box-shadow: 0 0 20rpx rgba($color: #000000, $alpha: 0.1);
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		z-index: 11;

		.item {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 20rpx 10rpx;
			flex: 1;
			flex-shrink: 0;

			button {
				width: 100%;
				border-radius: 50rem !important;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 0;
			}
		}
	}

	.product-image {
		width: 140rpx;
		height: 140rpx;
	}
</style>